package com.mallify.admin.controller;

import com.mallify.common.response.HomeRateResponse;
import com.mallify.common.response.Result;
import com.mallify.service.service.HomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 统计 -- 主页 前端控制器t_store_product_attr
 * +----------------------------------------------------------------------
 * | HANSON [ HANSON赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Licensed HANSON并不是自由软件，未经许可不能去掉HANSON相关版权
 * +----------------------------------------------------------------------
 * | Author: HANSON Team <hanson0622@126.com>
 * +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/admin/statistics/home")
@Api(tags = "统计 -- 主页")
public class HomeController {

    @Resource
    private HomeService homeService;

    @PreAuthorize("hasAnyAuthority('admin:statistics:home:index')")
    @ApiOperation(value = "首页数据")
    @GetMapping(value = "/index")
    public Result<HomeRateResponse> indexDate() {
        return Result.success(homeService.indexDate());
    }

//    @PreAuthorize("hasAnyAuthority('admin:statistics:home:chart:user')")
    @ApiOperation(value = "用户曲线图")
    @GetMapping(value = "/chart/user")
    public Result<Map<Object, Object>> chartUser() {
        return Result.success(homeService.chartUser());
    }

    /**
     * 30天订单量趋势
     */
    @PreAuthorize("hasAuthority('admin:statistics:home:chart:order')")
    @ApiModelProperty(value = "30天订单量趋势")
    @GetMapping(value = "/chart/order")
    public Result<Map<String, Object>> chartOrder() {
        return Result.success(homeService.chartOrder());
    }

    /**
     * 周订单量趋势
     */
    @PreAuthorize("hasAuthority('admin:statistics:home:chart:order:week')")
    @ApiModelProperty(value = "周订单量趋势")
    @GetMapping(value = "/chart/order/week")
    public Result<Map<String, Object>> chartOrderInWeek() {
        return Result.success(homeService.chartOrderInWeek());
    }

    /**
     * 月订单量趋势
     */
    @PreAuthorize("hasAuthority('admin:statistics:home:chart:order:month')")
    @ApiModelProperty(value = "月订单量趋势")
    @GetMapping(value = "/chart/order/month")
    public Result<Map<String, Object>> chartOrderInMonth() {
        return Result.success(homeService.chartOrderInMonth());
    }

    /**
     * 年订单量趋势
     */
    @PreAuthorize("hasAuthority('admin:statistics:home:chart:order:year')")
    @ApiModelProperty(value = "年订单量趋势")
    @GetMapping(value = "/chart/order/year")
    public Result<Map<String, Object>> chartOrderYear() {
        return Result.success(homeService.chartOrderInYear());
    }
}
